/**
 * @Title: DemoRabbitMqSender.java
 * @Description:
 * @author zsw
 * <p>
 * Copyright(C) 2018-2019    NPlus
 * Company:   无锡核心信息科技有限公司
 * @version V2.0.0
 * @Date: 10:55 2019/10/18
 * <p>
 * 修改历史:
 * Date                 Author        Version        Description
 * -----------------------------------------------------------------------------------
 * 10:55 2019/10/18       zsw        2.0.0           初始化版本
 */
package com.example.springjpa.sender;


import com.example.springjpa.model.Student;
import com.example.springjpa.rabbitmq.ConfirmCallbackService;
import com.example.springjpa.rabbitmq.ReturnCallbackService;
import net.sf.json.JSONObject;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DemoRabbitMqSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private ConfirmCallbackService confirmCallbackService;
    @Autowired
    private ReturnCallbackService returnCallbackService;

    public void send(String content) {
        System.out.println("Sender : " + content);
        Student student = new Student();
        student.setId(1L);
        student.setAge(18);
        student.setFlag(true);
        student.setStatus("哈哈");
        JSONObject jsonObject =JSONObject.fromObject(student);
        rabbitTemplate.setMandatory(true);

        rabbitTemplate.setConfirmCallback(confirmCallbackService);
        /*** 消息投递到队列失败回调处理 */
        rabbitTemplate.setReturnCallback(returnCallbackService);
        this.rabbitTemplate.convertAndSend("hello", jsonObject.toString());
        this.rabbitTemplate.convertAndSend("confirm_test_queue", jsonObject.toString());
        this.rabbitTemplate.convertAndSend("confirmFanoutExchange","confirm_test_queue", "这是confirmFanoutExchange");
    }

}
